//
//  sellerCenterViewController.m
//  CommunityApp
//
//  Created by 秦乾龙 on 16/12/20.
//  Copyright © 2016年 秦乾龙. All rights reserved.
//

#import "sellerCenterViewController.h"
#import "AFNetworking.h"//主要用于网络请求方法
#import "UIKit+AFNetworking.h"//里面有异步加载图片的方法
#import "AFHTTPSessionManager.h"
#import "UIButton+WebCache.h"
#import "UIImageView+WebCache.h"
#import "NavView.h"
#import "UserInfo.h"
#import "GoodsManageViewController.h"
#import "AuctionManageViewController.h"
#import "ChangePsdViewController.h"
#import "PaymentViewController.h"
#import "ZYTableViewCell.h"
#import "OrderManageViewController.h"

#define kScreenW [UIScreen mainScreen].bounds.size.width
#define kScreenH [UIScreen mainScreen].bounds.size.height
#define kScale   ([UIScreen mainScreen].bounds.size.width)/750
@interface sellerCenterViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,retain) UITableView *mainTableView;
@property (nonatomic,retain) NavView *nav;
@property (nonatomic,retain) NSArray *titleImageNameArr;
@property (nonatomic,retain) NSArray *titleArr;

@end

@implementation sellerCenterViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self setUI];
    [self request];
}

- (void) setUI
{
    self.navigationItem.titleView = [ViewFactory makeNavigationTitle:@"卖家中心"];
    
    UIBarButtonItem *backBtn = [ViewFactory makeNavigationBackWhite:self action:@selector(backClick)];
    self.navigationItem.leftBarButtonItem = backBtn;
    
    _mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0,kScreenW , kScreenH-64) style:UITableViewStyleGrouped];
    _mainTableView.delegate = self;
    _mainTableView.dataSource = self;
    [self.view addSubview:_mainTableView];
}
- (void)request
{
    NSString *urlStr = [NSString stringWithFormat:@"%@/product/showProductType",APIYIGOU]
    ;
    
    DYBaseRequest *request = [DYBaseRequest new];
    request.requestUrl = urlStr;
    [request dyBgStartWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        NSDictionary *allDic = [NSDictionary changeType:request.responseJSONObject];
        NSLog(@"1111111%@",allDic);
        NSMutableArray *classArr = allDic[@"data"];
        NSUserDefaults *defaults = [[NSUserDefaults alloc]init];
        [defaults setObject:classArr forKey:@"classArr"];
    } error:^(YTKBaseRequest *request) {
        
    } failure:^(YTKBaseRequest *request) {
        [ViewFactory showErrorStrMsg:NETWORK_ERR];
    }];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * identifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell)
    {
        cell =[[NSBundle mainBundle ]loadNibNamed:@"ZYTableViewCell" owner:nil options:nil][0];
    }
    //设置cell点击背景色不变
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    NSArray *titleImageNameArr = [[NSArray alloc]initWithObjects:@"商品管理图标",@"拍卖管理图标",@"订单管理图标",@"收款方式图标", nil];
    NSArray *titleArr = [[NSArray alloc]initWithObjects:@"商品管理",@"拍卖管理",@"订单管理",@"收款方式", nil];
    UIImageView *titleImage = [[UIImageView alloc]init];
    titleImage.frame = CGRectMake(32*kScale, (100-30)*kScale/2, 30*kScale, 30*kScale);
    UILabel *titleLable = [[UILabel alloc]init];
    //        titleImage.backgroundColor = [UIColor cyanColor];
    titleLable.frame = CGRectMake(80*kScale, (100-44)*kScale/2, kScreenW, 44*kScale);
    
    titleImage.image = [UIImage imageNamed:titleImageNameArr[indexPath.row]];
    titleLable.text = titleArr[indexPath.row];
    
    [cell addSubview:titleImage];
    [cell addSubview:titleLable];
    //右侧小箭头
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self performSelector:@selector(cancleSelect) withObject:nil afterDelay:0.1f];
    NSMutableArray *vcArr = [[NSMutableArray alloc]init];
    
    GoodsManageViewController  *vc1 = [[GoodsManageViewController alloc]init];
    [vcArr addObject:vc1];
     AuctionManageViewController *vc2 = [[AuctionManageViewController alloc]init];
    [vcArr addObject:vc2];
    OrderManageViewController  *vc3 = [[OrderManageViewController alloc]init];
    [vcArr addObject:vc3];
    PaymentViewController  *vc4 = [[PaymentViewController alloc]init];
    [vcArr addObject:vc4];
    [self.navigationController pushViewController:vcArr[indexPath.row] animated:YES];
    
}
- (void)cancleSelect
{
    [_mainTableView deselectRowAtIndexPath:[_mainTableView indexPathForSelectedRow] animated:YES];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return  100*kScale;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01;
}
//修改状态栏字体
- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}
- (void)backClick
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
